<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/common_include_for_server.jsp"%>
<link href="js/uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<%=request.getContextPath()%>/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="js/uploadify/swfobject.js"></script>
<script type="text/javascript" src="js/uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
<!--
var recommendInfo = {

};
//-->
</script>
<s:iterator value="report.reportRecos">
	<script> recommendInfo['${industry.industryId}'] = true; </script>
</s:iterator>
<script type="text/javascript">
var industryTree = null;
var treeData = '<s:property value="#application[@org.zhouhe.util.Constant@APPLICATION_KEY_INDUSTRY_XML ]" escape="false"/>';
$(document).ready(function() {
	industryTree = new dhtmlXTreeObject("treeBox","100%","100%",0);
	industryTree.setImagePath("js/dhtmlxTree/imgs/");
	industryTree.enableCheckBoxes(true, false);
	industryTree.enableThreeStateCheckboxes(true);
	industryTree.loadXMLString(treeData, function(){
		//load callback:
	}); 
	var options = {
		//filebrowserBrowseUrl : '//chinamirn',
		//filebrowserImageBrowseUrl : '/chinamirn',
		//filebrowserUploadUrl : '/chinamirn/manage/upload.action',
		filebrowserImageUploadUrl : '<%=request.getContextPath()%>/manage/upload.action'
	};
	CKEDITOR.replace( 'report.catalog', options );
	$('#upload_image').uploadify( {
		'uploader' : '<%=request.getContextPath()%>/js/uploadify/uploadify.swf',
		'script' : '<%=request.getContextPath()%>/manage/uploadify.action;jsessionid=<%=session.getId()%>',//firefox等浏览器中Flash无法获取会话ID，验证失败，跳转到登录界面！！
		'fileDataName' : 'files',
		'cancelImg' : '<%=request.getContextPath()%>/js/uploadify/cancel.png',
		'fileExt' : '*.jpg;*.gif;*.png',
		'fileDesc' : 'Image Files',
		'auto' : true,
		'buttonImg' : '<%=request.getContextPath()%>/images/upload.png',
		'width' : '66',
		'height' : '24',
		'scriptData': {dir:'report_img'},
		'onComplete' : function(evt, queueID, fileObj, response, data) {
			$('#report_imgName').val(response);
			$('#report_img').attr('src', response);
		}
	});
	$("#report_displayTime").datepicker({dateFormat: 'yy-mm-dd', changeYear: true, changeMonth: true});
	$("#report_publishDate").datepicker({dateFormat: 'yy-mm-dd', changeYear: true, changeMonth: true});
	//
	$("#selectIndustryDialog").dialog({
		title: '选择行业',
		autoOpen: false, 
		resizable: false,
		modal: true,
		open: function(event, ui) {
			industryTree.setCheck(0,false);
			$.each($('#industryValues input'), function(i, input){
				industryTree.setCheck($(input).val(), true);
			});
		},
		buttons: {
			"确定":function(){
				$('#industryValues').empty();
				$('#industryLabels').empty();
				$('#recoPanel').empty();
				var levelOneIds = {};
				var inds =  industryTree.getAllChecked().split(',');
				var tmpIndex = 0;
				for(var i=0; i<inds.length; i++){
					if(inds[i].length > 0){//这是个有效的行业ID
						var label = industryTree.getItemText(inds[i]) ;
						var pid = industryTree.getParentId(inds[i]);
						if(pid != '0'){
							var pLabel = industryTree.getItemText(pid);
							label = pLabel +' &gt;&gt; '+ label;
							$('#industryValues').append('<input type="hidden" value="'+ inds[i] +'" name="reportIndustries['+ i +'].industry.industryId"/>');
							$('#industryLabels').append('['+ label +']<br/>');
							if(!levelOneIds[pid]){
								var ifChecked = '';
								if(recommendInfo[pid]){
									ifChecked = ' checked="checked" ';
								}
								$('#recoPanel').append('<input type="checkbox" name="reportRecoList['+ (tmpIndex++) +'].industry.industryId" value="'+ pid +'" id="r'+ pid +'"  '+ ifChecked +'/>');
								$('#recoPanel').append('<label for="r'+ pid +'">'+ pLabel +'</label>');
								levelOneIds[pid] = true;
							}
						}
					}
				}
				$('#selectIndustryDialog').dialog('close');
			},
			"取消":function(){ $('#selectIndustryDialog').dialog('close'); }
		}
	});
});
function addIndustrySelector(){
	$('#selectIndustryDialog').dialog('open');
}
</script>
<div id="selectIndustryDialog">
	 <div id="treeBox" style="width:270;height:400"></div>
</div>
<s:form action="report!saveOrUpdateDo" method="post">
<table border="1" width="100%">
	<tr>
		<th width="100px;">
			标题
		</th>
		<td>
			<s:textfield name="report.title" value="%{report.title}" size="50"/>
		</td>
	</tr>
	<tr>
		<th width="100px;">
			版本
		</th>
		<td>
			<s:textfield name="report.version" value="%{report.version}" size="5"/>年版
		</td>
	</tr>
	<tr>
		<th>
			分类
		</th>
		<td>
			<s:select name="report.reportType.reportTypeId" value="report.reportType.reportTypeId" list="%{reportTypeList}" listKey="reportTypeId" listValue="name"></s:select>
		</td>
	</tr>
	<tr>
		<th>
			行业
		</th>
		<td>
			<span id="industryValues">
				<s:iterator value="report.reportIndustries" status="sts">
					<s:hidden name="reportIndustries[%{#sts.index }].industry.industryId" value="%{industry.industryId}"></s:hidden>
				</s:iterator>
			</span>
			<span id="industryLabels">
				<s:iterator value="report.reportIndustries" status="sts">
					[
					<s:if test="industry.industry != null">
						<s:property value="industry.industry.name"/> &gt;&gt;
					</s:if>
					<s:property value="industry.name"/>]<br/>
				</s:iterator>
			</span>
			<s:a href="javascript:void(0);" onclick="addIndustrySelector()">选择</s:a>
		</td>
	</tr>
	<tr>
		<th>推荐</th>
		<td>
			<div id="recoPanel">
				<s:iterator value="industryList" status="sts">
					<input type="checkbox" name="reportRecoList[${sts.index }].industry.industryId" value="${industryId}" id="r${industryId}" 
							<s:if test="orderId eq 1"> checked='checked' </s:if>
					/><label for="r${industryId}"><s:property value="name"/></label>
				</s:iterator>
			</div>
		</td>
	</tr>
	<tr>
		<th>时间</th>
		<td><input id="report_displayTime" name="report.displayTime" value='<s:date name="report.displayTime" format="yyyy-MM-dd"/>'/></td>
	</tr>
	<tr>
		<th>
			缩略图
		</th>
		<td>
			<table>
				<tr>
					<td>
						<span style="height: 100px; float: right;">
							<s:if test="report.imgName != null">
								<a href="${report.imgName}" target="_blank">
								<img id="report_img" style="height: 100px;border: 0;" src="${report.imgName}" />
								</a>
							</s:if>
							<s:else>
								<img id="report_img" style="height: 100px;border: 0;" src="images/no_pic.png" />
							</s:else>
							
						</span>
					</td>
					<td valign="top">
						<input type="file" id="upload_image" />
						<s:hidden id="report_imgName" name="report.imgName" value="%{report.imgName}" />
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<th>收费/免费</th>
		<td>
			<input type="radio" name="report.free" id="report_free_0" value="0" <s:if test="report.free!=1"> checked="checked"</s:if>/><label for="report_free_0">收费</label>
			<input type="radio" name="report.free" id="report_free_1" value="1" <s:if test="report.free==1"> checked="checked"</s:if>/><label for="report_free_1">免费</label>
		</td>
	</tr>
	<tr>
		<th>价格</th>
		<td>
			纸介版：<input type="text" name="report.pricePaper" value="${report.pricePaper }" size="5"/>&nbsp;&nbsp;
			电子版：<input type="text" name="report.priceElectron" value="${report.priceElectron }" size="5"/>&nbsp;&nbsp;
			纸介版+电子版：<input type="text" name="report.priceTotal" value="${report.priceTotal }" size="5"/>
			<span style="color:#999999">（单位：元）</span>
		</td>
	</tr>
	<tr>
		<th>发布日期</th>
		<td>
			<input id="report_publishDate" type="text" name="report.publishDate" value="<s:date name="report.publishDate" format="yyyy-MM-dd"/>" size="10"/>
		</td>
	</tr>
	<tr>
		<th>发布机构</th>
		<td>
			<s:textfield type="text" name="report.publishInstitution" value="%{report.publishInstitution}" size="50"/>
		</td>
	</tr>
	<tr>
		<th>表现形式</th>
		<td>
			<input type="text" name="report.manifestations" value="${report.manifestations}" size="50"/>
		</td>
	</tr>
	<tr>
		<th>订购电话</th>
		<td>
			<input type="text" name="report.orderTel" value="${report.orderTel}" size="50"/>
		</td>
	</tr>
	<tr>
		<th>交付时间</th>
		<td>
			<input type="text" name="report.deliveryTime" value="${report.deliveryTime}" size="6"/>个工作日
		</td>
	</tr>
	<tr>
		<th>交付方式</th>
		<td>
			<input type="text" name="report.deliveryMethod" value="${report.deliveryMethod}" size="50"/>
		</td>
	</tr>
	<tr>
		<th>传　　真</th>
		<td>
			<input type="text" name="report.fax" value="${report.fax}" size="50"/>
		</td>
	</tr>
	<tr>
		<th>关键字</th>
		<td><textarea name="report.keywords" cols="70" rows="2"><s:property value="%{report.keywords}"/></textarea></td>
	</tr>
	<tr>
		<th>
			摘要
		</th>
		<td>
			<textarea name="report.summary" rows="4" cols="50"><s:property value="%{report.summary}"/></textarea>
		</td>
	</tr>
	<tr>
		<th>
			目录
		</th>
		<td>
			<s:textarea name="report.catalog" rows="6" cols="60" ></s:textarea>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<s:hidden name="report.reportId" value="%{report.reportId}"></s:hidden>
			<s:hidden name="pageUtil.showPage" value="%{pageUtil.showPage}"></s:hidden>
			<s:submit value="提交"></s:submit>
		</td>
	</tr>
</table>
</s:form>